cmake_minimum_required(VERSION 3.16)

project(MLLM_ImgSorter VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network Multimedia Concurrent)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network Multimedia Concurrent)

set(PROJECT_SOURCES
    main.cpp
    mainwindow.cpp
    mainwindow.h
    FileManager.cpp
    FileManager.h
    ImageChatService.cpp
    ImageChatService.h
    Embedding.cpp
    Embedding.h
    Similarity.cpp
    Similarity.h
    FaceRecognition.cpp
    FaceRecognition.h
    FileInfo.h
    AiServiceSettings.cpp
    AiServiceSettings.h
    UpdateFunctions.cpp
    UpdateFunctions.h
    SettingsArea.cpp
    SettingsArea.h
    ImagePrevieWarea.cpp
    ImagePrevieWarea.h
    FileInfoarea.cpp
    FileInfoarea.h
    FileExporter.cpp
    FileExporter.h
    llamaServerManager.cpp
    llamaServerManager.h
    PathSettings.cpp
    PathSettings.h
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(MLLM_ImgSorter
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
else()
    if(ANDROID)
        add_library(MLLM_ImgSorter SHARED
            ${PROJECT_SOURCES}
        )
    else()
        add_executable(MLLM_ImgSorter
            ${PROJECT_SOURCES}
        )
    endif()
endif()

target_link_libraries(MLLM_ImgSorter PRIVATE 
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::Network
    Qt${QT_VERSION_MAJOR}::Multimedia
    Qt${QT_VERSION_MAJOR}::Concurrent
)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.MLLM_ImgSorter)
endif()
set_target_properties(MLLM_ImgSorter PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS MLLM_ImgSorter
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(MLLM_ImgSorter)
endif()
